//
//  AppsTableViewCell.m
//  应用管理02
//
//  Created by 伍银荣 on 2021/6/9.
//  Copyright © 2021 com.example. All rights reserved.
//

#import "AppsTableViewCell.h"
#import "AppsModel.h"

@interface AppsTableViewCell ()
@property (strong, nonatomic) IBOutlet UIImageView *imgView;

@property (strong, nonatomic) IBOutlet UILabel *nameLabel;
@property (strong, nonatomic) IBOutlet UILabel *introLabel;
@property (strong, nonatomic) IBOutlet UIButton *downloadBtn;

@end

@implementation AppsTableViewCell

-(void)setModel:(AppsModel *)model {
    _model = model;
    //将model数据赋值给控件的内容
    _imgView.image = [UIImage imageNamed:_model.icon];
    _nameLabel.text = _model.name;
    _introLabel.text = [NSString stringWithFormat:@"大小: %@ | 下载量: %@",_model.size,_model.download];
    //为了避免后面的cell复用到前面的cell,要在设置数据的时候刷新下载按钮的状态
    if (_model.isDownload) {
        _downloadBtn.enabled = NO;
    } else {
        _downloadBtn.enabled = YES;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - 下载按钮的点击事件
- (IBAction)downloadBtnClicked:(UIButton *)sender {
    NSLog(@"downloadBtnClicked");
    sender.enabled = NO;
    _model.isDownload = YES;
    if ([self.delegate respondsToSelector:@selector(createLabelWithAppsTableViewCell:)]) {
        [self.delegate createLabelWithAppsTableViewCell:self];
    }
}

@end
